package com.student.controller;

import com.student.pojo.Fe;
import com.student.pojo.Student;
import com.student.service.ClassesService;
import com.student.service.FeService;
import com.student.service.StudentService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;

import javax.servlet.http.HttpServletRequest;
import java.util.List;
/**
 * @author 是一个鸽子啊
 * @date 2020/4/14
 * @qq 364826415
 */
@Controller
public class FeController {
    @Autowired
    @Qualifier("feServiceImpl")
    FeService feService;
    @Autowired
    @Qualifier("StudentServiceImpl")
    private StudentService studentService;
    @Autowired
    @Qualifier("classesServiceImpl")
    private ClassesService classesService;
    @RequestMapping("/queryFeList")
    private String queryFeList(HttpServletRequest request){
        List<Fe> feList = feService.queryFeList();
        request.setAttribute("feList",feList);
        return "/tuition-settle";
    }
    @RequestMapping("/addFe")
    private String addFe(Fe fe,HttpServletRequest request){
        feService.addFe(fe);
        List<Fe> feList = feService.queryFeList();
        request.setAttribute("feList",feList);
        return "/tuition-settle";
    }
    @RequestMapping("updateFe")
    private String updateFe(Fe fe,HttpServletRequest request){
        feService.updateFe(fe);
        List<Fe> feList = feService.queryFeList();
        request.setAttribute("feList",feList);
        return "/tuition-settle";
    }
    @RequestMapping("/queryStudentFeList")
    private String queryStudentFeList(HttpServletRequest request){
        List<Student> studentFeList = studentService.queryStudent();
        for (Student student : studentFeList) {
            student.setClasses(classesService.queryClassesByID(student.getStudentCID()));
            student.setFe(feService.queryFeByID(student.getStudentFID()));
        }
        request.setAttribute("studentFeList",studentFeList);
        return "/tuition-table";
    }
    @RequestMapping("/updateStudentFe")
    private String updateStudentFe(Student student,HttpServletRequest request){
        studentService.updateStudentFe(student);
        List<Student> studentFeList = studentService.queryStudent();
        for (Student student1 : studentFeList) {
            student1.setClasses(classesService.queryClassesByID(student1.getStudentCID()));
            student1.setFe(feService.queryFeByID(student1.getStudentFID()));
        }
        request.setAttribute("studentFeList",studentFeList);
        return "/tuition-table";

    }
    @RequestMapping("/updateStudentFeW")
    private String updateStudentFeW(Student student,HttpServletRequest request){
        student.setStudentFeState("未缴费");
        studentService.updateStudentFeW(student);
        List<Student> studentFeList = studentService.queryStudent();
        for (Student student1 : studentFeList) {
            student1.setClasses(classesService.queryClassesByID(student1.getStudentCID()));
            student1.setFe(feService.queryFeByID(student1.getStudentFID()));
        }
        request.setAttribute("studentFeList",studentFeList);
        return "/tuition-table";

    }
    @RequestMapping("/updateStudentFeY")
    private String updateStudentFeY(Student student,HttpServletRequest request){
        student.setStudentFeState("已缴费");
        studentService.updateStudentFeY(student);
        List<Student> studentFeList = studentService.queryStudent();
        for (Student student1 : studentFeList) {
            student1.setClasses(classesService.queryClassesByID(student1.getStudentCID()));
            student1.setFe(feService.queryFeByID(student1.getStudentFID()));
        }
        request.setAttribute("studentFeList",studentFeList);
        return "/tuition-table";
    }
    @RequestMapping("/queryStudentByName")
    private String queryStudentByName(String studentName,HttpServletRequest request){
        List<Student> studentFeList = studentService.queryStudentByName(studentName);
        for (Student student1 : studentFeList) {
            student1.setClasses(classesService.queryClassesByID(student1.getStudentCID()));
            student1.setFe(feService.queryFeByID(student1.getStudentFID()));
        }
        request.setAttribute("studentFeList",studentFeList);
        return "/tuition-table";
    }
    @RequestMapping("/queryStudentByStudentFeState")
    private String queryStudentByStudentFeState(String studentFeState,HttpServletRequest request){
        List<Student> studentFeList = studentService.queryStudentByStudentFeState(studentFeState);
        for (Student student1 : studentFeList) {
            student1.setClasses(classesService.queryClassesByID(student1.getStudentCID()));
            student1.setFe(feService.queryFeByID(student1.getStudentFID()));
        }
        request.setAttribute("studentFeList",studentFeList);
        return "/tuition-table";
    }
}
